#!/bin/sh

echo "###############################################################"
echo "### NUPP应用程序运行状态检查脚本 "
echo "### "
echo "###############################################################"

APPPATH=/home/gpp/app/

check_one_app(){	
  app_name=nupp-$1
  pid=`ps ux | grep $app_name | grep java | grep -v "grep" | awk '{print $2}'`
  if [ -n "$pid" ] ; then
    if [ $app_name = "nupp-api-gateway" ]; then
      echo "$app_name	Server is running.	【OK】"
    else
      echo "$app_name		Server is running.	【OK】"
    fi
  else
    if [ $app_name = "nupp-api-gateway" ]; then
      echo "$app_name	Server is not running.	【FAIL】"
    else
      echo "$app_name		Server is not running.	【FAIL】"
    fi
  fi
}

check_nacos(){	
  pid=`ps ux | grep nacos | grep java | grep -v "grep" | awk '{print $2}'`
  if [ -n "$pid" ] ; then
    echo "nacos			Server is running.	【OK】"
  else
    echo "nacos			Server is not running.	【FAIL】"
  fi
}

check_nginx(){	
  pid=`ps ux | grep nginx | grep -v "grep" | awk '{print $2}'`
  if [ -n "$pid" ] ; then
    echo "nginx			Server is running.	【OK】"
  else
    echo "nginx			Server is not running.	【FAIL】"
  fi
}
#### MAIN ####
if [ $# == 0 ]; then
  # 启动所有程序
  check_nginx
  check_one_app "settings"
  check_one_app "notice"
  check_one_app "security"
  check_one_app "gateway"
  check_one_app "routing"
  check_one_app "channel"
  check_one_app "business"
  check_one_app "checking"
  check_one_app "workflow"
  check_one_app "scheduler"
  check_one_app "position"
  check_one_app "api-gateway"

elif [ $# == 1 ]; then
  case $1 in
    "channel"|"business"|"checking"|"workflow"|"scheduler"|"analysis"|"notice"|"position"|"settings"|"routing"|"gateway"|"security"|"api-gateway")
      check_one_app $1
      ;;
    "nginx")
      check_nginx
      ;;
    *)
      echo "invalid parameter [$1]..."
      ;;
  esac
fi



